package com.fanfanwang.ffw.app.widget.expandlist;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ListView;
import android.widget.RelativeLayout;

import com.fanfanwang.ffw.app.R;
import com.fanfanwang.ffw.app.adapter.TextAdapter;
import com.fanfanwang.ffw.app.bean.LengthListBean;


public class ViewRight extends RelativeLayout implements ViewBaseAction{

	private ListView mListView;
	//	private final String[] items = new String[] { "item1", "item2", "item3", "item4", "item5", "item6" };//显示字段
	//	private final String[] itemsVaule = new String[] { "1", "2", "3", "4", "5", "6" };//隐藏id
	private List<String> items=new ArrayList<String>();
	private List<String> itemsVaule=new ArrayList<String>();
	private OnSelectListener mOnSelectListener;
	private TextAdapter adapter;
	private String mDistance;
	private String showText = "item1";
	private Context mContext;
	private ArrayList<LengthListBean> data;
	public String getShowText() {
		return showText;
	}
	//这个构造暂时没用
	public ViewRight(Context context,ArrayList<LengthListBean> data) {
		super(context);
		this.data=data;
		init(context);
	}
	public ViewRight(Context context) {
		super(context);
		init(context);
	}

	public ViewRight(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context);
	}

	public ViewRight(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}
	public void resetData(ArrayList<LengthListBean> data){
		if(data!=null)
		{
			for(int i=0;i<data.size();i++)
			{
				items.add(data.get(i).val+"千米");
				itemsVaule.add(data.get(i).id);
			}
		}
		adapter.resetData(items);
		adapter.notifyDataSetChanged();
	}
	private void init(Context context) {
		mContext = context;
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.view_distance, this, true);
		setBackgroundDrawable(getResources().getDrawable(R.drawable.choosearea_bg_right));
		/*if(data!=null)
		{
			for(int i=0;i<data.size();i++)
			{
				items.add(data.get(i).val+"千米");
				itemsVaule.add(data.get(i).id);
			}
		}else{
			items.add("1千米");
			items.add("5千米");
			items.add("10千米");
			itemsVaule.add("0");
			itemsVaule.add("1");
			itemsVaule.add("2");
		}*/
		mListView = (ListView) findViewById(R.id.listView);
		adapter = new TextAdapter(context, items, R.drawable.choose_item_right, R.drawable.choose_eara_item_selector);
		adapter.setTextSize(17);
		if (mDistance != null) {
			/*for (int i = 0; i < itemsVaule.length; i++) {
				if (itemsVaule[i].equals(mDistance)) {
					adapter.setSelectedPositionNoNotify(i);
					showText = items[i];
					break;
				}
			}*/
			for(int i=0;i<itemsVaule.size();i++)
			{
				if ((itemsVaule.get(i)).equals(mDistance)) {
					adapter.setSelectedPositionNoNotify(i);
					showText = items.get(i);
					break;
				}
			}
		}
		mListView.setAdapter(adapter);
		adapter.setOnItemClickListener(new TextAdapter.OnItemClickListener() {

			@Override
			public void onItemClick(View view, int position) {

				if (mOnSelectListener != null) {
					showText = items.get(position);
					mOnSelectListener.getValue(itemsVaule.get(position), items.get(position));
				}
			}
		});
	}

	public void setOnSelectListener(OnSelectListener onSelectListener) {
		mOnSelectListener = onSelectListener;
	}

	public interface OnSelectListener {
		public void getValue(String distance, String showText);
	}

	@Override
	public void hide() {

	}

	@Override
	public void show() {

	}

}
